<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>管理员界面</title>
    <link rel="shortcut icon" th:href="@{/logo/favicon.ico}"/>
    <!-- Custom fonts for this template-->
    <link rel="stylesheet" type="text/css" th:href="@{/vendor/fontawesome-free/css/all.min.css}"/>
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
          rel="stylesheet">
    <!-- Custom styles for this template-->
    <link rel="stylesheet" type="text/css" th:href="@{/css/sb-admin-2.min.css}"/>
    <!-- Custom styles for this page -->
    <link rel="stylesheet" type="text/css" th:href="@{/vendor/datatables/dataTables.bootstrap4.min.css}"/>
</head>
<style>
    td button {
        margin-right: 8px;
        width: 40px;
    }

    td {
        border: 1px solid black;
    }

    #table_one td {
        border-top: 1px solid black;
    }

    [contenteditable="false"], [contenteditable="true"] {
        color: black;
        font-weight: bold;
    }

    .table th, .table td {
        text-align: center;
        vertical-align: middle !important;
    }

    td img {
        width: 50%;
    }
</style>
<body id="page-top">

<!-- Page Wrapper -->
<div id="wrapper">
    <!-- Sidebar -->
    <!-- Sidebar -->
    <div th:if="${role} == 4" style="height: auto;background-color: #224abe;">
        <div th:replace="commons/aduit_sidebar::#accordionSidebar"></div>
    </div>
    <!-- End of Sidebar -->
    <!-- Content Wrapper -->
    <div id="content-wrapper" class="d-flex flex-column">
        <!-- Main Content -->
        <div id="content">
            <!-- Topbar -->
            <div th:replace="commons/admin_navbar::#navbar"></div>
            <!-- Begin Page Content -->
            <div class="container-fluid">
                <!-- DataTales Example -->
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover text-nowrap" id="dataTable" cellspacing="0">
                                <thead>
                                <tr>
                                    <th>id</th>
                                    <th>流水号</th>
                                    <th>机械环保登记号</th>
                                    <th>定位终端号</th>
                                    <th>排放阶段</th>
                                    <th>车辆品牌</th>
                                    <th>机械类型</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.container-fluid -->
        </div>
        <!-- End of Main Content -->
        <!-- Footer -->
        <div th:replace="commons/footer::#footer"></div>
        <!-- End of Footer -->

    </div>
    <!-- End of Content Wrapper -->

</div>
<!-- End of Page Wrapper -->

<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
</a>

<!-- Logout Modal-->
<div th:replace="commons/logout::#logoutModal"></div>


<!-- Bootstrap core JavaScript-->
<script type="text/javascript" th:src="@{/vendor/jquery/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/vendor/bootstrap/js/bootstrap.bundle.min.js}"></script>

<script type="text/javascript" th:src="@{/js/admin_commons.js}"></script>
<!-- Core plugin JavaScript-->
<script type="text/javascript" th:src="@{/vendor/jquery-easing/jquery.easing.min.js}"></script>
<!-- Custom scripts for all pages-->

<script type="text/javascript" th:src="@{/js/sb-admin-2.min.js}"></script>

<!-- Page level plugins -->
<script type="text/javascript" th:src="@{/vendor/datatables/jquery.dataTables.min.js}"></script>
<script type="text/javascript" th:src="@{/vendor/datatables/dataTables.bootstrap4.min.js}"></script>
<script type="text/javascript" th:src="@{/js/demo/datatables-demo.js}"></script>
</body>
<script>
    $(function () {
        var table;
        //提示信息
        $.fn.dataTable.ext.errMode = 'none';
        var lang = {
            "bAutoWidth": false,
            "sProcessing": "处理中...",
            "sLengthMenu": "每页 _MENU_ 项",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
            "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "根据流水号搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页",
                "sJump": "跳转"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        };
        //初始化表格
        table = $("#dataTable")
            .on('error.dt', function (e, settings, techNote, message) {
                console.warn(message)
            }).dataTable({
                destroy: true,
                autoWidth: false,
                language: lang, //提示信息
                stripeClasses: ["odd", "even"], //为奇偶行加上样式，兼容不支持CSS伪类的场合
                processing: true, //隐藏加载提示,自行处理
                serverSide: true, //启用服务器端分页
                searching: false, //禁用原生搜索
                ordering: false,
                renderer: "bootstrap", //渲染样式：Bootstrap和jquery-ui
                pagingType: "simple_numbers", //分页样式：simple,simple_numbers,full,full_numbers
                ajax: function (data, callback, settings) {
                    var param = {};
                    param.pageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                    param.start = data.start;//开始的记录序号
                    param.currentPage = (data.start / data.length) + 1;//当前页码
                    console.log(param);
                    $.ajax({
                        type: "GET",
                        beforeSend: function (request) {
                            request.setRequestHeader("uid", localStorage.getItem("token"));
                        },
                        url: "/vehicle/view-all",
                        data: param,
                        cache: false, //禁用缓存
                        dataType: "json",
                        success: function (result) {
                            var returnData = {};
                            returnData.draw = data.startRow;//这里直接自行返回了draw计数器,应该由后台返回
                            returnData.recordsTotal = result.totalRows;//返回数据全部记录
                            returnData.recordsFiltered = result.totalRows;//后台不实现过滤功能，每次查询均视作全部结果
                            returnData.data = result.items;//返回的数据列表
                            //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕
                            callback(returnData);
                        }
                    }, 200);
                },
                "columns": [
                    {"data": "vehicleId", visible: false},
                    {"data": "processNo"},
                    {"data": "mhyPlate"},
                    {"data": "deviceId"},
                    {"data": "emissionLevel"},
                    {"data": "mhyBrand"},
                    {"data": "mhyType"},
                    {
                        render: function (data, type, full) {
                            return "<button onclick='view_vehicle_info(" + full.vehicleId + ");'  class='btn btn-info btn-icon-split'> <span class='text'>查看</span></button>";
                        },
                    },
                ],
            })
            .api();
        //此处需调用api()方法,否则返回的是JQuery对象而不是DataTables的API对象
    })

    function view_vehicle_info(vehicleId) {
        window.open("/vehicle/view?vId=" + vehicleId);
    }
</script>
</html>
